package com.api.shopapi.service.impl;

import com.api.shopapi.entity.Recharge;
import com.api.shopapi.entity.dto.RechargeDTO;
import com.api.shopapi.mapper.RechargeMapper;
import com.api.shopapi.service.RechargeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("RechargeServiceImplOne")
public class RechargeServiceImpl implements RechargeService {

    @Autowired
    private RechargeMapper rechargeMapper;



    @Override
    public int insert(RechargeDTO rechargeDTO) {
        return rechargeMapper.insert(rechargeDTO);
    }

    @Override
    public PageInfo<RechargeDTO> getPageList(int pageIndex, int pageSize, String name,String phone,String governmentCode) {
//        double payMoneyAll = rechargeMapper.getTotalPayMoney(name,phone,governmentCode);
//        double addBalanceAll = rechargeMapper.getTotalAddBalance(name,phone,governmentCode);
        PageHelper.startPage(pageIndex,pageSize);
        List<RechargeDTO> rechargeDTOList=rechargeMapper.getPageList(name,phone,governmentCode);
//        for (RechargeDTO rechargeDTO : rechargeDTOList) {
//            rechargeDTO.setPayMoneyAll(payMoneyAll);
////            rechargeDTO.setAddBalanceAll(addBalanceAll);
//        }
        return new PageInfo<>(rechargeDTOList);
    }

    @Override
    public PageInfo<RechargeDTO> getForInfo(int pageIndex, int pageSize, String rechargeGroupCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<RechargeDTO> rechargeDTOList =rechargeMapper.getForInfo(rechargeGroupCode);
        return new PageInfo<>(rechargeDTOList);
    }

    @Override
    public PageInfo<RechargeDTO> getPageList1(int pageIndex, int pageSize, String name, String phone, String governmentCode, String startTime, String endTime) {
        double payMoneyAll = rechargeMapper.getTotalPayMoney(name,phone,governmentCode,startTime,endTime);
        double addBalanceAll = rechargeMapper.getTotalAddBalance(name,phone,governmentCode,startTime,endTime);
        PageHelper.startPage(pageIndex,pageSize);
        List<RechargeDTO> rechargeDTOList=rechargeMapper.getPageList1(name,phone,governmentCode,startTime,endTime);
        for (RechargeDTO rechargeDTO : rechargeDTOList) {
            rechargeDTO.setPayMoneyAll(payMoneyAll);
            rechargeDTO.setAddBalanceAll(addBalanceAll);
        }
        return new PageInfo<>(rechargeDTOList);
    }

    @Override
    public List<Recharge> getAddBalance(String elderlyCode, Date startTime, Date endTime) {
        return rechargeMapper.getAddBalance(elderlyCode,startTime,endTime);
    }


}
